//#include "stdafx.h"
#include "CameraResult.h"

#include"common/commonDefFun.h"
#include "Plugins/dirHelper/cDirHelper.h"

#include<stdio.h>
#include<string.h>

using namespace libtool_sdk::Helper;

namespace libcvos_vfr
{

	typedef struct {
		long long iObjecSize;
	}ResultInfo;

	CameraIMG& CameraIMG::operator=(const CameraIMG& CaIMG)
	{
		if (this != &CaIMG)
		{
			wImgWidth = CaIMG.wImgWidth;
			wImgHeight = CaIMG.wImgHeight;
			dwImgSize = CaIMG.dwImgSize;
			wImgType = CaIMG.wImgType;
			memcpy(chSavePath, CaIMG.chSavePath, sizeof(CaIMG.chSavePath));
			if (CaIMG.dwImgSize != 0
				&& NULL != CaIMG.pbImgData)
			{
				pbImgData = new unsigned char[CaIMG.dwImgSize];
				memcpy(pbImgData, CaIMG.pbImgData, dwImgSize);
			}
			else
			{
				pbImgData = NULL;
			}
		}
		return *this;
	}

	CameraIMG::CameraIMG() :
		pbImgData(NULL)
	{
		wImgWidth = 0;
		wImgHeight = 0;
		dwImgSize = 0;
		memset(chSavePath, '\0', sizeof(chSavePath));
	}

	CameraIMG::CameraIMG(const CameraIMG& CaIMG)
	{
		if (this == &CaIMG)
		{
			return;
		}
		wImgWidth = CaIMG.wImgWidth;
		wImgHeight = CaIMG.wImgHeight;
		dwImgSize = CaIMG.dwImgSize;
		wImgType = CaIMG.wImgType;
		memcpy(chSavePath, CaIMG.chSavePath, sizeof(CaIMG.chSavePath));
		if (CaIMG.dwImgSize != 0
			&& NULL != CaIMG.pbImgData)
		{
			pbImgData = new unsigned char[CaIMG.dwImgSize];
			memcpy(pbImgData, CaIMG.pbImgData, dwImgSize);
		}
		else
		{
			pbImgData = NULL;
		}
	}

	CameraIMG::~CameraIMG()
	{
		wImgWidth = 0;
		wImgHeight = 0;
		if (NULL != pbImgData)
		{
			delete[] pbImgData;
			pbImgData = NULL;
		}
		dwImgSize = 0;
		memset(chSavePath, 0, sizeof(chSavePath));
	}
	//-------------------------------------------------------------------------------------------------------------
	//-------------------------------------------------------------------------------------------------------------

    CameraResult::CameraResult():
        pcAppendInfo(NULL)
	{
		dwCarID = 0;
		iDeviceID = 0;
		iPlateColor = 0;
		iPlateTypeNo = 0;
		iTailPlateColor = 9;
		dw64TimeMS = 0;
		dwFront64TimeMS = 0;
		iSpeed = 0;
		iResultNo = 0;
		iVehTypeNo = 0;		//车型代码: ��?1--1 。。。客4--4��? ��?1--5  。。。货4--8
		iVehSizeType = 0;
		iVehBodyColorNo = 0;
		iVehBodyDeepNo = 0;
		iVehLogoType = 0;
		iAreaNo = 0;
		iRoadNo = 0;
		iLaneNo = 0;
		iDirection = 0;
		iWheelCount = 0;		//轮数
		iAxletreeCount = 0;		//轴数
		iAxletreeType = 0;		//轴型
		iAxletreeGroupCount = 2;
		iReliability = 0;
		dwReceiveTime = 0;
		fVehLenth = 0;			//车长
		fDistanceBetweenAxles = 0.0;		//轴距
		fVehHeight = 0.0;		//车高
		fVehWidth = 0.0;
		fConfidenceLevel = 0.0;
		bBackUpVeh = false;		//是否倒车
		iWeightLimit = 0;

		fAxisConfidience = 0.0;	//轮轴可信��?
        fWindowHeight = 0.0;

		iDriveShaftIndex = 0;	//驱动轴位��?
		iDriveShaftCount = 0;	//驱动轴个��?
		iWeightLimit =0;				//限重
        iTriggerID = 0;
        iIsDangers = 0;
        iCardMPos = 0;

		memset(chDeviceIp, '\0', sizeof(chDeviceIp));
		memset(chServerIP, '\0', sizeof(chServerIP));
		memset(chPlateNO, '\0', sizeof(chPlateNO));
		memset(chPlateColor, '\0', sizeof(chPlateColor));
		memset(chListNo, '\0', sizeof(chListNo));
		memset(chPlateTime, '\0', sizeof(chPlateTime));
		memset(chSignStationID, '\0', sizeof(chSignStationID));
		memset(chSignStationName, '\0', sizeof(chSignStationName));
		memset(chSignDirection, '\0', sizeof(chSignDirection));
		memset(chDeviceID, '\0', sizeof(chDeviceID));
		memset(chLaneID, '\0', sizeof(chLaneID));
		memset(chCarFace, '\0', sizeof(chCarFace));
		memset(chChileLogo, '\0', sizeof(chChileLogo));
        //memset(pcAppendInfo, '\0', sizeof(pcAppendInfo));
		memset(chTailPlateNo, '\0', sizeof(chTailPlateNo));
		memset(chVehicleType, '\0', sizeof(chVehicleType));
		memset(chSavePath, '\0', sizeof(chSavePath));
		memset(chAxiInfo, '\0', sizeof(chAxiInfo));		
	}

    CameraResult::CameraResult(const CameraResult& CaRESULT):
        pcAppendInfo(NULL)
	{
		if (this == &CaRESULT)
		{
			return;
		}
		dwCarID = CaRESULT.dwCarID;
		dw64TimeMS = CaRESULT.dw64TimeMS;
		dwFront64TimeMS = CaRESULT.dwFront64TimeMS;
		iLaneNo = CaRESULT.iLaneNo;
		iPlateColor = CaRESULT.iPlateColor;
		iTailPlateColor = CaRESULT.iTailPlateColor;
		iVehTypeNo = CaRESULT.iVehTypeNo;
		iVehSizeType = CaRESULT.iVehSizeType;
		iDirection = CaRESULT.iDirection;
		iAreaNo = CaRESULT.iAreaNo;
		iVehBodyColorNo = CaRESULT.iVehBodyColorNo;
		iPlateTypeNo = CaRESULT.iPlateTypeNo;
		iVehBodyDeepNo = CaRESULT.iVehBodyDeepNo;
		iVehLogoType = CaRESULT.iVehLogoType;
		iDeviceID = CaRESULT.iDeviceID;
		iRoadNo = CaRESULT.iRoadNo;
		iSpeed = CaRESULT.iSpeed;
		iAxletreeType = CaRESULT.iAxletreeType;
		iAxletreeCount = CaRESULT.iAxletreeCount;
		iAxletreeGroupCount = CaRESULT.iAxletreeGroupCount;
		iResultNo = CaRESULT.iResultNo;
		iWheelCount = CaRESULT.iWheelCount;
		iReliability = CaRESULT.iReliability;

		fVehHeight = CaRESULT.fVehHeight;
		fVehWidth = CaRESULT.fVehWidth;
		fVehLenth = CaRESULT.fVehLenth;
		fDistanceBetweenAxles = CaRESULT.fDistanceBetweenAxles;
		fConfidenceLevel = CaRESULT.fConfidenceLevel;
		fAxisConfidience = CaRESULT.fAxisConfidience;
        fWindowHeight = CaRESULT.fWindowHeight;

		bBackUpVeh = CaRESULT.bBackUpVeh;
		dwReceiveTime = CaRESULT.dwReceiveTime;

		iDriveShaftIndex = CaRESULT.iDriveShaftIndex;;	//驱动轴位��?
		iDriveShaftCount = CaRESULT.iDriveShaftCount;;	//驱动轴个��?
		iWeightLimit = CaRESULT.iWeightLimit;
        iTriggerID = CaRESULT.iTriggerID;

        iIsDangers = CaRESULT.iIsDangers;
        iCardMPos = CaRESULT.iCardMPos;

		memcpy(chDeviceIp, CaRESULT.chDeviceIp, sizeof(chDeviceIp));
		memcpy(chServerIP, CaRESULT.chServerIP, sizeof(chServerIP));
		memcpy(chPlateNO, CaRESULT.chPlateNO, sizeof(chPlateNO));
		memcpy(chPlateColor, CaRESULT.chPlateColor, sizeof(chPlateColor));
		memcpy(chListNo, CaRESULT.chListNo, sizeof(chListNo));
		memcpy(chPlateTime, CaRESULT.chPlateTime, sizeof(chPlateTime));
		memcpy(chSignStationID, CaRESULT.chSignStationID, sizeof(chSignStationID));
		memcpy(chSignStationName, CaRESULT.chSignStationName, sizeof(chSignStationName));
		memcpy(chSignDirection, CaRESULT.chSignDirection, sizeof(chSignDirection));
		memcpy(chDeviceID, CaRESULT.chDeviceID, sizeof(chDeviceID));
		memcpy(chLaneID, CaRESULT.chLaneID, sizeof(chLaneID));
		memcpy(chCarFace, CaRESULT.chCarFace, sizeof(chCarFace));
		memcpy(chChileLogo, CaRESULT.chChileLogo, sizeof(chChileLogo));
        //memcpy(pcAppendInfo, CaRESULT.pcAppendInfo, sizeof(pcAppendInfo));
		memcpy(chTailPlateNo, CaRESULT.chTailPlateNo, sizeof(chTailPlateNo));
		memcpy(chVehicleType, CaRESULT.chVehicleType, sizeof(chVehicleType));
		memcpy(chSavePath, CaRESULT.chSavePath, sizeof(chSavePath));
		memcpy(chAxiInfo, CaRESULT.chAxiInfo, sizeof(chAxiInfo));

        if(CaRESULT.pcAppendInfo != NULL)
        {
            size_t len = strlen(CaRESULT.pcAppendInfo);
            pcAppendInfo = new char[len +1];
            memcpy(pcAppendInfo, CaRESULT.pcAppendInfo, len);
            pcAppendInfo[len] ='\0';
        }

		CIMG_BestCapture = CaRESULT.CIMG_BestCapture;
		CIMG_BeginCapture = CaRESULT.CIMG_BeginCapture;
		CIMG_LastCapture = CaRESULT.CIMG_LastCapture;
		CIMG_BestSnapshot = CaRESULT.CIMG_BestSnapshot;
		CIMG_LastSnapshot = CaRESULT.CIMG_LastSnapshot;
		CIMG_PlateImage = CaRESULT.CIMG_PlateImage;
		CIMG_BinImage = CaRESULT.CIMG_BinImage;

#ifdef SAVE_VIDEO
		videoFrameList = CaRESULT.videoFrameList;
#endif
	}

	CameraResult::~CameraResult()
	{
		dwCarID = 0;
		iDeviceID = 0;
		iPlateColor = 0;
		iPlateTypeNo = 0;
		dw64TimeMS = 0;
		iSpeed = 0;
		iResultNo = 0;
		iVehTypeNo = 0;		//车型代码: ��?1--1 。。。客4--4��? ��?1--5  。。。货4--8
		iVehBodyColorNo = 0;
		iVehBodyDeepNo = 0;
		iVehLogoType = 0;
		iAreaNo = 0;
		iRoadNo = 0;
		iLaneNo = 0;
		iDirection = 0;
		iWheelCount = 0;		//轮数
		iAxletreeCount = 0;		//轴数
		iAxletreeGroupCount = 0;
		iAxletreeType = 0;		//轴型
		iReliability = 0;
		fVehLenth = 0;			//车长
		fDistanceBetweenAxles = 0.0;		//轴距
		fVehHeight = 0.0;		//车高
		bBackUpVeh = false;		//是否倒车
        iTriggerID = 0;

        memset(chDeviceIp, '\0', sizeof(chDeviceIp));
        memset(chPlateNO, '\0', sizeof(chPlateNO));
		memset(chPlateColor, '0', sizeof(chPlateColor));
		memset(chListNo, '0', sizeof(chListNo));
		memset(chPlateTime, '0', sizeof(chPlateTime));
		memset(chSignStationID, '0', sizeof(chSignStationID));
		memset(chSignStationName, '0', sizeof(chSignStationName));
		//memset(pcAppendInfo, '0', sizeof(pcAppendInfo));
		memset(chLaneID, '0', sizeof(chLaneID));
		memset(chDeviceID, '0', sizeof(chDeviceID));
		memset(chAxiInfo, '0', sizeof(chAxiInfo));

        if(pcAppendInfo)
        {
            delete[] pcAppendInfo;
            pcAppendInfo = NULL;
        }

#ifdef SAVE_VIDEO
		videoFrameList.clear();
#endif
	}

	void CopyCImgDataToFile(CameraIMG& imageStruct, FILE* pFile)
	{
		if (NULL == pFile || imageStruct.dwImgSize <= 0)
		{
			return;
		}
		if (imageStruct.dwImgSize > 0 && NULL != imageStruct.pbImgData)
		{
			fwrite(imageStruct.pbImgData, sizeof(unsigned char), imageStruct.dwImgSize, pFile);
		}
	}

	void CopyCImgDataFromBuffer(CameraIMG& imageStruct, unsigned char* pBuffer)
	{
		if (imageStruct.dwImgSize > 0)
		{
			imageStruct.pbImgData = new unsigned char[imageStruct.dwImgSize];
			memcpy(imageStruct.pbImgData, pBuffer, imageStruct.dwImgSize);
		}
		else
		{
			imageStruct.pbImgData = NULL;
		}
	}

	CameraResult& CameraResult::operator=(const CameraResult& CaRESULT)
	{
		if (this == &CaRESULT)
		{
			return *this;
		}
		dwCarID = CaRESULT.dwCarID;
		dw64TimeMS = CaRESULT.dw64TimeMS;
		dwFront64TimeMS = CaRESULT.dwFront64TimeMS;
		iLaneNo = CaRESULT.iLaneNo;
		iPlateColor = CaRESULT.iPlateColor;
		iTailPlateColor = CaRESULT.iTailPlateColor;
		iVehTypeNo = CaRESULT.iVehTypeNo;
		iVehSizeType = CaRESULT.iVehSizeType;
		iDirection = CaRESULT.iDirection;
		iAreaNo = CaRESULT.iAreaNo;
		iVehBodyColorNo = CaRESULT.iVehBodyColorNo;
		iPlateTypeNo = CaRESULT.iPlateTypeNo;
		iVehBodyDeepNo = CaRESULT.iVehBodyDeepNo;
		iVehLogoType = CaRESULT.iVehLogoType;
		iDeviceID = CaRESULT.iDeviceID;
		iRoadNo = CaRESULT.iRoadNo;
		iSpeed = CaRESULT.iSpeed;
		iAxletreeType = CaRESULT.iAxletreeType;
		iAxletreeCount = CaRESULT.iAxletreeCount;
		iAxletreeGroupCount = CaRESULT.iAxletreeGroupCount;
		iResultNo = CaRESULT.iResultNo;
		iWheelCount = CaRESULT.iWheelCount;
		iReliability = CaRESULT.iReliability;
		fVehHeight = CaRESULT.fVehHeight;
		fVehWidth = CaRESULT.fVehWidth;
		fVehLenth = CaRESULT.fVehLenth;
		fDistanceBetweenAxles = CaRESULT.fDistanceBetweenAxles;
		fConfidenceLevel = CaRESULT.fConfidenceLevel;
		bBackUpVeh = CaRESULT.bBackUpVeh;
        dwReceiveTime = CaRESULT.dwReceiveTime;

		fAxisConfidience = CaRESULT.fAxisConfidience;	//轮轴可信��?
        fWindowHeight = CaRESULT.fWindowHeight;

		iDriveShaftIndex = CaRESULT.iDriveShaftIndex;	//驱动轴位��?
		iDriveShaftCount = CaRESULT.iDriveShaftCount;	//驱动轴个��?
		iWeightLimit = CaRESULT.iWeightLimit;				//限重
        iTriggerID = CaRESULT.iTriggerID;

        iIsDangers = CaRESULT.iIsDangers;
        iCardMPos = CaRESULT.iCardMPos;

		memcpy(chDeviceIp, CaRESULT.chDeviceIp, sizeof(chDeviceIp));
		memcpy(chServerIP, CaRESULT.chServerIP, sizeof(chServerIP));
		memcpy(chPlateNO, CaRESULT.chPlateNO, sizeof(chPlateNO));
		memcpy(chPlateColor, CaRESULT.chPlateColor, sizeof(chPlateColor));
		memcpy(chListNo, CaRESULT.chListNo, sizeof(chListNo));
		memcpy(chPlateTime, CaRESULT.chPlateTime, sizeof(chPlateTime));
		memcpy(chSignStationID, CaRESULT.chSignStationID, sizeof(chSignStationID));
		memcpy(chSignStationName, CaRESULT.chSignStationName, sizeof(chSignStationName));
		memcpy(chSignDirection, CaRESULT.chSignDirection, sizeof(chSignDirection));
		memcpy(chDeviceID, CaRESULT.chDeviceID, sizeof(chDeviceID));
		memcpy(chLaneID, CaRESULT.chLaneID, sizeof(chLaneID));
		memcpy(chCarFace, CaRESULT.chCarFace, sizeof(chCarFace));
		memcpy(chChileLogo, CaRESULT.chChileLogo, sizeof(chChileLogo));
        //memcpy(pcAppendInfo, CaRESULT.pcAppendInfo, sizeof(pcAppendInfo));
		memcpy(chTailPlateNo, CaRESULT.chTailPlateNo, sizeof(chTailPlateNo));
		memcpy(chVehicleType, CaRESULT.chVehicleType, sizeof(chVehicleType));
		memcpy(chSavePath, CaRESULT.chSavePath, sizeof(chSavePath));

        if(pcAppendInfo)
        {
            delete[] pcAppendInfo;
            pcAppendInfo = NULL;
        }
        if(CaRESULT.pcAppendInfo != NULL)
        {
            size_t len = strlen(CaRESULT.pcAppendInfo);
            pcAppendInfo = new char[len +1];
            strcpy(pcAppendInfo, CaRESULT.pcAppendInfo);
        }

		CIMG_BestCapture = CaRESULT.CIMG_BestCapture;
		CIMG_BeginCapture = CaRESULT.CIMG_BeginCapture;
		CIMG_LastCapture = CaRESULT.CIMG_LastCapture;
		CIMG_BestSnapshot = CaRESULT.CIMG_BestSnapshot;
		CIMG_LastSnapshot = CaRESULT.CIMG_LastSnapshot;
		CIMG_PlateImage = CaRESULT.CIMG_PlateImage;
		CIMG_BinImage = CaRESULT.CIMG_BinImage;
#ifdef SAVE_VIDEO
		videoFrameList = CaRESULT.videoFrameList;
#endif
		return *this;
	}

}
